//
//  CirclePostsDetailsViewController.m
//  安好
//
//  Created by rlp on 14-12-3.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "CirclePostsDetailsViewController.h"
#import "PopoverView1.h"
#import "MyFocusViewcontroller.h"

#import "iflyMSC/IFlyRecognizerView.h"
#import "iflyMSC/IFlyRecognizerViewDelegate.h"
#define APPID @"5313e44f"

@interface CirclePostsDetailsViewController ()@property(nonatomic,strong) UILabel *description1;
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UIView *topView;

@property(nonatomic,assign)BOOL isExpanded;
@end

@implementation CirclePostsDetailsViewController
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[AFHTTPRequestOperationManager manager].operationQueue cancelAllOperations];
    [self hiddenActionView];
    if (self.pop) {
        [self.pop dismiss];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.squarePage =1;
    self.type= 0;
    self.edgesForExtendedLayout=UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    
    if (!self.threadListBaseClass) {
        self.threadListBaseClass=[[ThreadListBaseClass alloc]init];
    }
    if ([[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] isKindOfClass:[MyFocusViewcontroller class]]) {
        self.squareView = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, kScreenWidth, kScreenHeight-64) style:UITableViewStylePlain];

    }else{
        self.squareView = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, kScreenWidth, kScreenHeight-64-((kScreenWidth-15*2)*3.f/29.f+10)) style:UITableViewStylePlain];

    }
    self.squareView.delegate = self;
    self.squareView.dataSource = self;
    [self.squareView setSeparatorStyle:UITableViewCellSeparatorStyleNone];//去掉系统的分割线
    [self.view addSubview:self.squareView];
    [self.squareView addFooterWithTarget:self action:@selector(loadSquareData)];
    [self.squareView addHeaderWithTarget:self action:@selector(uploadSquareData)];

    
    [self.squareView  footerBeginRefreshing];

    
    [self makeNavBarView];
    if ([[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] isKindOfClass:[MyFocusViewcontroller class]]) {
        /*
        self.fkSearchBar = [[FKSearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
        self.fkSearchBar.fkSearchRequestDelegate = self;
        self.squareView.tableHeaderView = self.fkSearchBar;
        [self.squareView setContentOffset:CGPointMake(0, self.fkSearchBar.frame.size.height) animated:YES];
*/

    }else{
    [self initWithHeaderView];
        
        /**
         发表话题按钮
         */
        //    UIButton *publicationBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, kScreenHeight-64-40, kScreenWidth-15*2, 30)];
        UIButton *publicationBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, kScreenHeight-64-((kScreenWidth-15*2)*3.f/29.f+10), kScreenWidth-15*2, (kScreenWidth-15*2)*3.f/29.f)];
        
        
        
        
        publicationBtn.layer.masksToBounds = YES;
        publicationBtn.layer.cornerRadius = 3.0;
        publicationBtn.layer.borderWidth = 0.0;
        [publicationBtn addTarget:self action:@selector(publicationTopicClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [publicationBtn setBackgroundColor:[ClassMethodsViewController colorWithHexString:NACIGATIONBAR_BACKGROUNDCOLOR_16]];
        [publicationBtn setTitle:@"发布话题" forState:UIControlStateNormal];
        publicationBtn.titleLabel.textColor = [UIColor whiteColor];
        publicationBtn.titleLabel.font = [UIFont systemFontOfSize:BUTTON_TEXTLABEL_FOUNT_SIZE];
        [self.view addSubview:publicationBtn];
    }

    

    

    UITapGestureRecognizer *tapna = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toTop)];
    [self.navigationController.navigationBar addGestureRecognizer:tapna];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(redDot) name:@"REDDOT" object:nil];

    
    
}
-(void)toTop{
//    [self.squareView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]
//                           atScrollPosition:UITableViewScrollPositionTop
//                                   animated:YES];
    //CGRectMake(0, 0, 1, 1)可以直接返回到UITableView的最顶端
    [self.self.squareView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
    
}
-(void)initWithHeaderView{
    
    
    self.fkSearchBar = [[FKSearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    self.fkSearchBar.fkSearchRequestDelegate = self;
    
    

    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, self.fkSearchBar.frame.size.height, kScreenWidth, ((kScreenWidth == 414)?40+2:40))];
    self.headerView.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#ecf4f6"];
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelTap:)];
    [self.headerView addGestureRecognizer:tapGes];
    
    //    self.tableView.tableHeaderView = self.headerView;
    
    UIImageView *tagImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 10, ((kScreenWidth == 414)?20+2:20), ((kScreenWidth == 414)?20+2:20))];
    [tagImage setImageURLStr:self.groupUserModel.icon placeholder:nil];
    [self.headerView addSubview:tagImage];
    
    
    
    //hui
    UIButton *buttonThreads = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, ((kScreenWidth == 414)?15*1.2:15))];
    [buttonThreads setImage:[UIImage imageNamed:@"圈子_人数"] forState:UIControlStateNormal];
    [buttonThreads setTitle:[NSString stringWithFormat:@" %ld ",(long)[self.groupUserModel.threads integerValue]] forState:UIControlStateNormal];
    [buttonThreads setTitleColor:TITLE_ARTICLE_CONTENTFONT_COLOR forState:UIControlStateNormal];
    buttonThreads.titleLabel.font = [UIFont systemFontOfSize:DVSWITCH_YEXT_FONT];
    buttonThreads.userInteractionEnabled = NO;
    [buttonThreads sizeToFit];
    
    UIButton *buttonPosts = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, ((kScreenWidth == 414)?15*1.2:15))];
    [buttonPosts setImage:[UIImage imageNamed:@"圈子_评论"] forState:UIControlStateNormal];
    [buttonPosts setTitle:[NSString stringWithFormat:@" %ld ",(long)[self.groupUserModel.posts integerValue]] forState:UIControlStateNormal];
    [buttonPosts setTitleColor:TITLE_ARTICLE_CONTENTFONT_COLOR forState:UIControlStateNormal];
    buttonPosts.titleLabel.font = [UIFont systemFontOfSize:DVSWITCH_YEXT_FONT];
    buttonPosts.userInteractionEnabled = NO;
    [buttonPosts sizeToFit];
    buttonPosts.frame = CGRectMake(buttonThreads.frame.size.width, buttonPosts.frame.origin.y, buttonPosts.frame.size.width, buttonPosts.frame.size.height);
    
    UIView *viewbutton = [[UIView alloc]initWithFrame:CGRectMake(kScreenWidth-buttonPosts.frame.size.width-buttonThreads.frame.size.width-15, tagImage.frame.origin.y, buttonPosts.frame.size.width+buttonThreads.frame.size.width, buttonThreads.frame.size.height)];
    
    [viewbutton addSubview:buttonThreads];
    [viewbutton addSubview:buttonPosts];
    
    [self.headerView addSubview:viewbutton];
    
    
    
    
    
    
    
    
    UILabel *titleName =[[UILabel alloc]initWithFrame:CGRectMake(tagImage.frame.size.width+tagImage.frame.origin.y+10, tagImage.frame.origin.y, viewbutton.frame.origin.x-10-(tagImage.frame.size.width+tagImage.frame.origin.y+5), 20) text:[NSString stringWithFormat:@"%@",self.groupUserModel.title] font:[UIFont systemFontOfSize:TITLE_TEXTLABEL_FOUNT_SIZE] textColor:TITLE_ARTICLE_TEXTFONT_COLOR backgroundColor:[UIColor clearColor] numberOfLines:0 lineSpacing:2];
    
    
    
    
    
    [self.headerView addSubview:titleName];
    
    
    
    self.description1 =[[UILabel alloc]initWithFrame:CGRectMake(15, ((kScreenWidth == 414)?40*1.2:40), kScreenWidth-15*2, 0) text:[NSString stringWithFormat:@"%@",self.groupUserModel.description1] font:[UIFont systemFontOfSize:LABEL_FONT_SIZE_CONTENT] textColor:TITLE_ARTICLE_CONTENTFONT_COLOR backgroundColor:[UIColor clearColor] numberOfLines:0 lineSpacing:5];
    [self.headerView addSubview:self.description1];
    self.description1.alpha = 0.f;
    
    
    
    
    self.topView = [[UIView alloc]initWithFrame:CGRectMake(0, 44, kScreenWidth, self.headerView.frame.size.height+self.headerView.frame.origin.y)];
    [self.topView addSubview:self.fkSearchBar];
    if (self.isFromMyFoucus) {
        
    }else{
        [self.topView addSubview:self.headerView];
    }
    
    
    
    self.squareView.tableHeaderView = self.topView;
    
    
    
    [self.squareView setContentOffset:CGPointMake(0, self.fkSearchBar.frame.size.height) animated:YES];

    
}
-(IBAction)handelTap:(id)sender{
    
    
    [UIView animateWithDuration:0.6 animations:^
     {
         if (self.isExpanded) {//是展开的
             self.headerView.frame =CGRectMake(0, self.headerView.frame.origin.y, kScreenWidth, 40);
             self.topView.frame =CGRectMake(0, self.topView.frame.origin.y, kScreenWidth, self.headerView.frame.size.height+self.headerView.frame.origin.y);
             
             
             
             
             [UIView animateWithDuration:0.4 animations:^
              {
                  self.description1.alpha = 0.f;
                  
              } completion:^(BOOL finished)
              {
              }];
         }else{
             
             self.headerView.frame =CGRectMake(0, self.headerView.frame.origin.y, kScreenWidth, self.description1.frame.size.height+self.description1.frame.origin.y+10);
             self.topView.frame =CGRectMake(0, self.headerView.frame.origin.y, kScreenWidth,  self.headerView.frame.size.height+self.headerView.frame.origin.y);
             
             
             [UIView animateWithDuration:0.8 animations:^
              {
                  self.description1.alpha = 1.f;
                  
              } completion:^(BOOL finished)
              {
              }];
             
         }
         
         self.squareView.tableHeaderView = self.topView;
         
     } completion:^(BOOL finished)
     {
     }];
    self.isExpanded = !self.isExpanded;
}



#pragma mark - 设置导航条
-(void)makeNavBarView
{
    self.navigationItem.title = [NSString stringWithFormat:@"%@",self.groupUserModel.title];
    //贴图
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClicked:)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
    UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 23, 23)];
    [rightButton setImage:[UIImage imageNamed:@"公用_更多"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    if ([[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] isKindOfClass:[MyFocusViewcontroller class]]) {

    }else{
        self.navigationItem.rightBarButtonItem = rightBarButtonItem;
        [self redDot];

    }

    
}
#pragma mark -
#pragma mark -- click
-(void)leftButtonClicked:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)rightButtonClicked:(UIButton *)sender
{
    //签到显示
    NSString *signStr = nil;
    if ([[NSString stringWithFormat:@"%.f",self.threadListBaseClass.issign] isEqualToString:@"1"]) {
        signStr = @"已签到";
    }else{
        signStr = @"一键签到";
    }
    
    //退出圈子 关注圈子显示
    NSString *collectStr = nil;
    if ([[NSString stringWithFormat:@"%.f",self.threadListBaseClass.iscollect] isEqualToString:@"1"]) {
        collectStr = @"退出圈子";
    }else{
        collectStr = @"关注圈子";

    }
    
    
    
    
    
    CGPoint point = CGPointMake(sender.frame.origin.x + sender.frame.size.width/2, 64);
    NSArray *titles = @[@"与我相关",@"查看全部", @"置顶贴", @"精华贴",@"最新贴",@"有图贴",@"无图贴",signStr,collectStr];
    NSArray *images = @[@"回复我的_normal",@"广场_全部", @"广场_置顶", @"广场_精华",@"广场_新帖",@"广场_有图",@"广场_无图",@"一键签到_normal",@"退出圈子_normal"];
    NSArray *selectImages = @[@"回复我的_pressed",@"广场_全部", @"广场_置顶", @"广场_精华",@"广场_新帖",@"广场_有图",@"广场_无图",@"一键签到_pressed",@"退出圈子_pressed"];

    
    
    self.pop = [[PopoverView alloc] initWithPoint:point titles:titles images:images selectImage:selectImages];
    __block CirclePostsDetailsViewController *mySelf = self;
    self.pop.selectRowAtIndex = ^(NSInteger index){
        MyNSLog("select index:%ld", (long)index);
        switch (index) {
                //	筛选类型:默认为0  1：置顶2：精华3：new 4：是否图片5：无图帖6：推荐
                
                
            case 0:
            {
                AssociatedWithIViewController *associatedWithIViewController = [[AssociatedWithIViewController alloc]initWithNibName:@"AssociatedWithIViewController" bundle:nil];
                associatedWithIViewController.title = @"与我相关";
                [mySelf.navigationController pushViewController:associatedWithIViewController animated:YES];
                
            }
                break;
            case 1:
            {
                if (mySelf.type!=0) {
                    mySelf.type = 0;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                    
                }
            }
                break;
            case 2:
            {
                if (mySelf.type!=1) {
                    mySelf.type = 1;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
            case 3:
            {
                if (mySelf.type!=2) {
                    mySelf.type = 2;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
            case 4:
            {
                if (mySelf.type!=3) {
                    mySelf.type = 3;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
            case 5:
            {
                if (mySelf.type!=4) {
                    mySelf.type = 4;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
            case 6:
            {
                if (mySelf.type!=5) {
                    mySelf.type = 5;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
            case 7:
            {
                mySelf.flagTypes = FlagTypesSign;
                [mySelf isLogin];
             
            }
                break;
            case 8:
            {
                mySelf.flagTypes = FlagTypesAttention;
                [mySelf isLogin];

            }
                break;
                
            default:
            {
                if (mySelf.type!=0) {
                    mySelf.type = 0;
                    mySelf.squarePage = 1;
                    //[self.threadListBaseClass.data removeAllObjects];;
                    [mySelf loadSquareData];
                    
                }
            }
                break;
        }
    };
    [self.pop show];
}


-(IBAction)publicationTopicClick:(id)sender{
    
    self.flagTypes = FlagTypesPost;
    [self isLogin];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)uploadSquareData{
    self.squarePage = 1;
    //[self.threadListBaseClass.data removeAllObjects];
    [self loadSquareData];
}
#pragma mark -
#pragma mark -- 数据加载
-(void)loadSquareData{
    
    
    MyNSLog("%@",[self.groupUserModel gid]);
    //    [self.squareView footerBeginRefreshing];
    [self showActionView];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    
    NSString *isFromMyFocuse;
    if (self.isFromMyFoucus) {
        isFromMyFocuse = [NSString stringWithFormat:@"/collection/list/"];
        [dict setObject:@"7" forKey:@"type"];
        self.navigationItem.title = @"收藏";
    }else{
        isFromMyFocuse = [NSString stringWithFormat:@"%@",THREAD_LIST];
//        [dict setObject:[NSString stringWithFormat:@"%d",self.squarePage] forKey:@"page"];//页码：默认第一页 	必选
        [dict setObject:@"20" forKey:@"pagesize"];//每页显示数量：默认每页20条
        [dict setObject:[self.groupUserModel gid] forKey:@"gid"];//	圈子id: 默认为0
        [dict setObject:[self.groupUserModel pid] forKey:@"pid"];//	一级圈子id：默认为0
        [dict setObject:[NSString stringWithFormat:@"%ld",(long)self.type] forKey:@"type"];//	筛选类型:默认为0  1：置顶2：精华3：new 4：是否图片5：无图帖6：推荐
        [dict setObject:@"dateline" forKey:@"order"];//order	排序dateline： 最新发表lastpost： 最新回复top置顶排序
        [dict setObject:self.fkSearchBar.searchTextField.text forKey:@"q"];

    }
    
    [dict setObject:kPlatform forKey:@"platform"];//平台 ios/android	必选
    [dict setObject:kVersion forKey:@"version"];//	版本号	必选
    [dict setObject:[NSString stringWithFormat:@"%ld",(long)self.squarePage] forKey:@"page"];//页码：默认第一页 	必选

    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL,isFromMyFocuse] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
            [self.squareView reloadData];

        }else{
            if (self.squarePage==1) {
                [self.threadListBaseClass.data removeAllObjects];
            }
            
            if ([self.threadListBaseClass.data count]==0) {
                self.threadListBaseClass = [ThreadListBaseClass modelObjectWithDictionary:responseObject];
                
            }else{
                [self.threadListBaseClass.data addObjectsFromArray:[(ThreadListBaseClass*)[ThreadListBaseClass modelObjectWithDictionary:responseObject] data]];
            }
            
            
            NSArray *jsonDictArr = [self.threadListBaseClass.data isEqual:[NSNull null]]?nil:self.threadListBaseClass.data;
            MyNSLog("%@",jsonDictArr);
            if (jsonDictArr!=nil) {
                self.squarePage++;
                
                
            }else{
                if (self.squarePage>1) {
                    MyNSLog("下拉无数据");
                }
            }
            
        }
        [self.squareView reloadData];

        [self hiddenActionView];
        [self.squareView footerEndRefreshing];
        [self.squareView headerEndRefreshing];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.squareView headerEndRefreshing];
        [self.squareView footerEndRefreshing];
        [self hiddenActionView];
        [self.squareView reloadData];


    }];
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    NSInteger number=0;
    
        number = self.threadListBaseClass.data.count;

    return number;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
      CGFloat  hight = [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
      return hight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    static NSString *ID=@"tableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
        if (cell == nil) {
            //            cell = [[[NSBundle mainBundle] loadNibNamed:@"SquareTableViewCell" owner:self options:nil] lastObject];
            cell = [[SquareATableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        }
        
        [[(SquareATableViewCell*)cell title] setText:[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] subject]]];
        [[(SquareATableViewCell*)cell content] setText:[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data  objectAtIndex:indexPath.row] summary]]];
        
        
        
        NSMutableArray *arrimages = [[NSMutableArray alloc ]initWithArray:[(ThreadListData*)[self.threadListBaseClass.data  objectAtIndex:indexPath.row] pic]];
        
        
        [(SquareATableViewCell*)cell setSquareCellImageViewsArray:arrimages];
        
        [[(SquareATableViewCell*)cell timesLabel] setText:[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data  objectAtIndex:indexPath.row] dateline]]];
        
        [(SquareATableViewCell*)cell bottomView].tag =indexPath.row;
        
        
        NSArray *numberArry =[[NSArray alloc]initWithObjects:
                              [NSString stringWithFormat:@"%d",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] collection]],
                              [NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] good]],
                              [NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] replies]],nil];
        
        [(SquareATableViewCell*)cell setArrayNumber:numberArry];
        
        
        NSMutableArray *array =[[NSMutableArray alloc]initWithCapacity:10];
        /**
         *          digest	是否加精1：是0：否
         *
         */
        if ([[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] digest]] isEqualToString:@"1"]) {
            [array addObject:[NSNumber numberWithInteger:SquareMarkStyleRefinement]];
        }
        /**
         *              top	是否置顶1：是0：否
         
         *
         */
        if ([[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] top]] isEqualToString:@"1"]) {
            [array addObject:[NSNumber numberWithInteger:SquareMarkStylePeak]];
        }
        /**
         * new	是否new 1：是0：否
         *
         */
        if ([[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] aNew]] isEqualToString:@"1"]) {
            [array addObject:[NSNumber numberWithInteger:SquareMarkStyleNew]];
        }
        /**
         * ispic	是否图片 1：是0：否
         *
         */
        if ([[NSString stringWithFormat:@"%@",[(ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row] ispic]] isEqualToString:@"0"]) {
//            [array addObject:[NSNumber numberWithInteger:SquareMarkStyleNot]];
        }else{
            [array addObject:[NSNumber numberWithInteger:SquareMarkStyleAdsum]];
            
        }
        
        
        
        //        SquareMarkStyleAll = 0,//全
        //        SquareMarkStyleRefinement,//精
        //        SquareMarkStylePeak,//顶
        //        SquareMarkStyleNew,//新
        //        SquareMarkStyleAdsum,//有
        //        SquareMarkStyleNot//无
        //
        //        isrec	是否推荐1：是0：否
        //        new	是否new 1：是0：否
        //        ispic	是否图片 1：是0：否
        //        closed	是否关闭回复1：是0：否
        
        
        
        [(SquareATableViewCell*)cell setSquareMarkStyles:array];
        
        [(SquareATableViewCell*)cell squareCellImageView].tag = indexPath.row;
        
        [(SquareATableViewCell*)cell setDelegate:self];
        
        
        
        
        
    

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        SquarePostsDetailsViewController *spdVC = [[SquarePostsDetailsViewController alloc] initWithNibName:@"SquarePostsDetailsViewController" bundle:nil];
        
        spdVC.threadListData = (ThreadListData*)[self.threadListBaseClass.data objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:spdVC animated:YES];
    
    
}
#pragma mark -
#pragma mark -- SquareCellImageViewsDelegate
-(void)squareCellImageViewsIndex:(NSInteger)index subImageIndex:(NSInteger)imageIndex{
    MyNSLog("第%ld个cell的第 %ld 个image", (long)index,(long)imageIndex);
}
-(void)bottomViewIndex:(NSInteger)index subImageIndex:(NSInteger)buttonIndex{
    MyNSLog("第%ld个cell的第 %ld 个button", (long)index,(long)buttonIndex);
    
    
}
#pragma mark -
#pragma mark -- FKSearchBarDelegate


- (void)VoiceConversion{
    [self.fkSearchBar.searchTextField resignFirstResponder];
    [self starVoice];
}
- (void)voice:(NSString *)voice
{
    self.fkSearchBar.searchTextField.text = voice;
    self.squarePage = 1;
    //[self.threadListBaseClass.data removeAllObjects];;
    [self loadSquareData];
}
- (void)SearchString{
    [self.view endEditing:NO];
//    [self.fkSearchBar.searchTextField resignFirstResponder];
    self.squarePage=1;
    //[self.threadListBaseClass.data removeAllObjects];;
    [self loadSquareData];
    
}

/**
 *  一键签到
 */
-(void)sign{
    [self showActionView];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    
    [dict setObject:kPlatform forKey:@"platform"];
    [dict setObject:kVersion forKey:@"version"];
    
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL,USER_SIGN] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("%@",responseObject);
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            if ([[responseObject objectForKey:@"msg"] length]>0) {
                [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
                
            }else{
                [self showCustomHudSingleLine:@"签到失败"];
                
            }
            
        }else{
            self.threadListBaseClass.issign = 1;
            if ([[responseObject objectForKey:@"msg"] length]>0) {
                [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
                
            }else{
                [self showCustomHudSingleLine:@"签到成功"];
                
            }
            
        }
        [self hiddenActionView];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        
    }];

}


-(void)Login{
    
    switch (self.flagTypes) {
        case FlagTypesSign:
        {
//          if ([[NSString stringWithFormat:@"%.f",self.threadListBaseClass.issign] isEqualToString:@"1"]) {
//              //已经签到
//          }else{
              [self sign];

//          }
        }
            break;
        case FlagTypesPost:
        {
            if ([[NSString stringWithFormat:@"%.f",self.threadListBaseClass.iscollect] isEqualToString:@"1"]) {
                //已经关注
                PublicationTopicViewController *ptVC = [[PublicationTopicViewController alloc]initWithNibName:@"PublicationTopicViewController" bundle:nil];
                ptVC.delegate = self;
                ptVC.groupUserModel = self.groupUserModel;
                [ptVC.subject becomeFirstResponder];

                [self.navigationController pushViewController:ptVC animated:YES];
            }else{
                UIAlertView *guanzhuAlert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"关注后才能发表话题,是否关注" delegate:self cancelButtonTitle:@"关注" otherButtonTitles:@"放弃", nil];
                        [guanzhuAlert show];
            }
            
            
        }
            break;
        case FlagTypesAttention:
        {
            if ([[NSString stringWithFormat:@"%.f",self.threadListBaseClass.iscollect] isEqualToString:@"1"]) {
                //已经关注
                [self guanzhu:OUT];

            }else{
                [self guanzhu:JOIN];

            }
            
            
        }
            break;
            
            

            
        default:
            break;
    }
    
    
 
}
//添加取消关注
-(void)guanzhu:(NSString *)actionStr{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    
    [dict setObject:kPlatform forKey:@"platform"];
    [dict setObject:kVersion forKey:@"version"];
    [dict setObject:actionStr forKey:@"action"];
    [dict setObject:self.groupUserModel.gid forKey:@"gid"];
    
    
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL,GROUP_CHANGEUSERGROUP] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("%@",responseObject);
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            if ([[responseObject objectForKey:@"msg"] length]>0) {
                [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
                
            }else{
                if ([actionStr isEqualToString:JOIN]) {
                    [self showCustomHudSingleLine:@"关注失败"];
                    
                }else if ([actionStr isEqualToString:OUT]) {
                    [self showCustomHudSingleLine:@"取消失败"];
                    
                }
            }
        }else{
            
            if ([actionStr isEqualToString:JOIN]) {
                self.threadListBaseClass.iscollect = 1;
                
            }else if ([actionStr isEqualToString:OUT]) {
                self.threadListBaseClass.iscollect = 0;
                
            }
            
            if ([[responseObject objectForKey:@"msg"] length]>0) {
                [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
                
            }else{
                if ([actionStr isEqualToString:JOIN]) {
                    [self showCustomHudSingleLine:@"关注成功"];
                    self.threadListBaseClass.iscollect=1;

                }else if ([actionStr isEqualToString:OUT]) {
                    [self showCustomHudSingleLine:@"取消成功"];
                    self.threadListBaseClass.iscollect= 0;

                }
                
            }
        }
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self showCustomHudSingleLine:@"请检查网络"];
        
    }];
}

#pragma mark -
#pragma mark -- UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
        {
            [self guanzhu:JOIN];//关注
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark -
#pragma mark -- PublicationTopicViewControllerDelegate
-(void)publicationTopicViewControllerWirhReloadData{
//    self.squarePage=1;
//    //[self.threadListBaseClass.data removeAllObjects];;
//    [self loadSquareData];
    [self uploadSquareData];
}
-(void)redDot{
    UIButton  *rightButton = (UIButton *)[self.navigationItem.rightBarButtonItem customView];
    if ([[[rightButton imageView] image] isEqual:[UIImage imageNamed:@"公用_更多"]]) {
        
        
        
        if ([[[SystemMessageCenter instance] selectAllNoReadedSecretaryNoticeMessage] count]<=0) {
            for (UIView *view in rightButton.subviews) {
                if ([view isKindOfClass:[UIImageView class]]) {
                    if ([[(UIImageView*)view  image] isEqual:[UIImage imageNamed:@"point2"]]) {
                        [view removeFromSuperview];
                    }
                }
                
            }
        }else{
            
            UIImageView *redDot = [[UIImageView alloc]initWithFrame:CGRectMake(rightButton.frame.size.width-10, 0, 10, 12)];
            redDot.image =[UIImage imageNamed:@"point2"];
            [rightButton addSubview:redDot];
        }
        
    }
}

@end
